# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: handle_coordinate_util.py
  @time: 2022/11/16 9:19
  @desc:
"""


def handle_coordinate(x_data, y_data):
    global x_coordinate, y_coordinate
    x_coordinate = handle_data(x_data)
    y_coordinate = handle_data(y_data)
    return x_coordinate, y_coordinate


def handle_data(value):
    global coordinate
    if float(value) < 0.5:
        coordinate = 0
    elif 0.5 <= float(value) <= 1.5:
        coordinate = 1
    else:
        decimal_fraction = round(float(value) - int(value), 4)
        if float(decimal_fraction) < 0.5:
            coordinate = int(value)
        elif 0.5 <= float(decimal_fraction) < 1:
            coordinate = int(value) + 1
    return coordinate

# print(handle_coordinate(1.5889673993451775, -0.011857941494125335))
